package sample;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import service.Jedis;

@Controller
@RequestMapping("/dict")
public class dictSample {
	@Resource(name="jedis-client")
	Jedis jedis;
	

	
	@RequestMapping(value="/hget/{key}/{field}")
	public String hget(@PathVariable("key")String key,@PathVariable("field")String field,Model model){
		model.addAttribute("code","String hget(String key, String field);");
		model.addAttribute("result",jedis.hget(key, field));
		return "result";
	}
	@RequestMapping(value="/hlen/{key}")
	public String hlen(@PathVariable("key")String key,Model model){
		model.addAttribute("code","long hlen(String key);");
		model.addAttribute("result",jedis.hlen(key));
		return "result";
	}
	
	@RequestMapping(value="/hmget/{key}/{fields}")
	public String hmget(@PathVariable("key")String key,@PathVariable("fields")String fields,Model model){
		String field[]=fields.split(":");
		model.addAttribute("code","List<Object> hmget(String key, String... fields);");
		model.addAttribute("result",jedis.hmget(key, field));
		return "result";
	}
	
	@RequestMapping(value="/hset/{key}/{field}/{value}")
	public String hset(@PathVariable("key")String key,@PathVariable("field")String field,@PathVariable("value") String value,Model model){
		model.addAttribute("code","long hset(String key, String field, String value);");
		model.addAttribute("result",jedis.hset(key, field, value)); 
		return "result";
	}
	
	@RequestMapping(value="/hexists/{key}/{field}")
	public String hexists(@PathVariable("key")String key,@PathVariable("field")String field,Model model){
		model.addAttribute("code","boolean hexists(String key, String field);");
		model.addAttribute("result",jedis.hexists(key, field)); 
		return "result";
	}
	
	@RequestMapping(value="/hsetnx/{key}/{field}/{value}")
	public String hsetnx(@PathVariable("key")String key,@PathVariable("field")String field,@PathVariable("value") String value,Model model){
		model.addAttribute("code","long hsetnx(String key, String field, String value);");
		model.addAttribute("result",jedis.hsetnx(key, field, value)); 
		return "result";
	}
}
